export const state = () => ({
    historys: [
        {   //出发城市
            // departCity: '广州',
            //到达城市
            // destCity: '上海',
            //出发日期
            // departDate: '2222-22-22'
        }
    ]
})

export const mutations = {
    //每一个项目都是函数
    setHistory(state, data) {
        //显示历史记录长度
        if (state.historys.length >= 7) {
            state.historys.pop()
        }
        if (data.departCity === '' || data.destCity === '' || data.departDate === '') {
            return
        }
        //历史记录去重
        let flag = true;
        state.historys.forEach(elm => {
            if (
                data.departCity == elm.departCity &&
                data.destCity == elm.destCity &&
                data.departDate == elm.departDate
            ) {
                console.log('历史记录已存在');
                flag = false;
            }
        });
        if (flag) {
            // state.historys = []   清空历史记录数据使用
            state.historys.unshift(data)
            console.log('++++');
        }
    }
}

